<?
	/**
	 * smarty template function
	 * name: rss fetch resource
	 * package: InTerra Blog Machine
	 * author: Kulikov Alexey <alex [at] inses [dot] ru
	 * 
	 * params:
	 *   mandatory: 	'source' rss source (string) 
	 *   optional:		'items' items to fetch (int)				default: 10
	 * 					'var' smarty variable name (string) 		default: rss
	 * 					'cache' whether to cache the result	(bool)	default: true
	 * 					'cachelt' lifetime of cache in seconds (int)default: 86400 seconds or one day
	 * @version 1.2
	 * @copyright 2004, InSES Corporation and Alexey Kulikov
	 * 
	 * @note 	make sure you have a template named empty.txt that contains nothing
	 * 			but {$someData} in it. This template will be used to cache RSS feeds
	 * 			locally. Also note that caching can be disabled, but this makes
	 * 			syndication with slow servers rather inefficient
	 **/
	 
 	function smarty_function_atom($params, &$smarty){
		//error check
		if(empty($params['source'])) {
			$smarty->trigger_error("rss: missing 'source' parameter");
        	return;
		}
		
		//check for optional variables
		//smarty variable name
		if(!empty($params['var'])){
			$variableName = (string)$params['var'];
		}else{
			$variableName = "rss";
		}
		
		//items to fetch
		if(!empty($params['items'])){
			$itemsToGet = (int)$params['items'];
		}else{
			$itemsToGet = 10;
		}
		
		//cache feed?
		if(!empty($params['cache'])){
			if($params['cache'] == 'false'){
				$cache = false;
			}else{
				$cache = true;
			}
		}else{
			$cache = true;
		}
		
		//cache lifetime
		if(!empty($params['cachelt'])){
			$lifeTime = (int)$params['cachelt'];
		}else{
			$lifeTime = 86400;
		}
		
		$counter    = 0;
#		if(function_exists('simplexml_load_file')){
#		echo $params['source'];exit;
#		}

echo file_get_contents($params['source']);exit;

        $data       = array();
        $feed       = simplexml_load_file($params['source']);
        foreach($feed->entry as $entry) {        
            $counter++;
            $t = array();
            $t['title']   = (string)$entry->title;
            $t['content'] = (string)$entry->content;
            $t['intime']  = (string)$entry->published;
            $data[]       = $t;
            
            if($counter > $itemsToGet){
                break;
            }
        }
        		
		//give data to smarty and terminate
		$smarty->assign($variableName,$data);		
		return;
	}	
?>